package com.ruoyi.ui.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.ui.mapper.UiAreaMapper;
import com.ruoyi.ui.domain.UiArea;
import com.ruoyi.ui.service.IUiAreaService;
import org.springframework.util.CollectionUtils;

/**
 * 地址Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-09-07
 */
@Service
public class UiAreaServiceImpl implements IUiAreaService
{
    @Autowired
    private UiAreaMapper uiAreaMapper;

    /**
     * 查询地址
     * 
     * @param areaId 地址主键
     * @return 地址
     */
    @Override
    public UiArea selectUiAreaByAreaId(Long areaId)
    {
        return uiAreaMapper.selectUiAreaByAreaId(areaId);
    }

    /**
     * 查询地址列表
     * 
     * @param uiArea 地址
     * @return 地址
     */
    @Override
    public List<UiArea> selectUiAreaList(UiArea uiArea)
    {
        return uiAreaMapper.selectUiAreaList(uiArea);
    }

    /**
     * 新增地址
     * 
     * @param uiArea 地址
     * @return 结果
     */
    @Override
    public int insertUiArea(UiArea uiArea)
    {
        return uiAreaMapper.insertUiArea(uiArea);
    }

    /**
     * 修改地址
     * 
     * @param uiArea 地址
     * @return 结果
     */
    @Override
    public int updateUiArea(UiArea uiArea)
    {
        return uiAreaMapper.updateUiArea(uiArea);
    }

    /**
     * 批量删除地址
     * 
     * @param areaIds 需要删除的地址主键
     * @return 结果
     */
    @Override
    public int deleteUiAreaByAreaIds(Long[] areaIds)
    {
        return uiAreaMapper.deleteUiAreaByAreaIds(areaIds);
    }

    /**
     * 删除地址信息
     * 
     * @param areaId 地址主键
     * @return 结果
     */
    @Override
    public int deleteUiAreaByAreaId(Long areaId)
    {
        return uiAreaMapper.deleteUiAreaByAreaId(areaId);
    }

    @Override
    public UiArea findUiAreaById(Long areaId) {

        UiArea uiArea = uiAreaMapper.findUiAreaById(areaId);
        if (uiArea !=null){
            List<UiArea> childAreas=uiAreaMapper.findChildByParentId(uiArea.getParentId());
            if (CollectionUtils.isEmpty(childAreas)){

            }else {
                uiArea.setAreas(childAreas);
                recursive(childAreas);
            }
        }
        return uiArea;
    }
    @Override
    public void recursive(List<UiArea> areas) {
        for (UiArea uiArea : areas) {
            List<UiArea> childAreas = uiAreaMapper.findChildByParentId(uiArea.getParentId());
            if (CollectionUtils.isEmpty(childAreas)) {

            }else {
                uiArea.setAreas(childAreas);
                recursive(childAreas);
            }
        } }

    @Override
    public List findChildByParentId(Long parentId){
        return uiAreaMapper.findChildByParentId(parentId);
    }
    @Override
    public List<UiArea> findlist(int level){

        return uiAreaMapper.findlist(level);
    }


}
